import time

start = time.time()
for i in range(5):
    with open(f'file_{i}.txt', 'w') as f:
        f.write("hello world\n" * 10_000_000)
print("同步写耗时：", time.time() - start)


import threading
import time

def write_file(i):
    with open(f'file_{i}.txt', 'w') as f:
        f.write("hello world\n" * 10_000_000)

start = time.time()
threads = []
for i in range(5):
    t = threading.Thread(target=write_file, args=(i,))
    t.start()
    threads.append(t)
for t in threads:
    t.join()

print("多线程写耗时：", time.time() - start)
